home *** CD-ROM | disk | FTP | other *** search
- // Routines pour l'affichage V0.16
- // (C) Christophe PASSUELLO
- // Sat Feb 20 15:18:58 1993
-
-
- #include <exec/types.h>
- #include <mytypes.h>
- #include <graphics/text.h>
- #include <graphics/rastport.h>
- #define INTUITION_PREFERENCES_H 0
- #include "IObject_priv.h"
-
- IMPORT __far CPTR DiskfontBase; // Diskfont Library
- IMPORT UBYTE BackPen;
-
- // Contantes pour le centrage
- #define VERT_DELTA 3
- #define HORIZ_DELTA 8
-
- // Fonte par defaut
- const static struct TextAttr safe_font=
- {
- "topaz.font",
- 8,
- FS_NORMAL,
- FPF_ROMFONT
- };
-
-
- //
- // Charge une fonte, si elle n'existe pas renvoie la Topaz 8
- //
- struct TextFont *LoadFont(struct TextAttr *Attribute)
- {
- struct TextFont *Font;
-
- if (!Attribute)
- Attribute = &safe_font;
-
- if (Font = OpenFont(Attribute))
- return (Font);
- else
- {
- // verifie que la Diskfont est ouverte
- if (DiskfontBase)
- {
- if (Font = OpenDiskFont(Attribute))
- return (Font);
- }
- return(OpenFont(&safe_font));
- }
- }
-
-
- //
- // Calcule la taille en pixels d'une chaine avec HotKey
- //
- UWORD MyTextWidth(struct RastPort *rp, STRPTR text, BOOL hotkey)
- {
- STRPTR next;
- UWORD size;
-
- size = 0;
- if (hotkey)
- {
- size = TextLength(rp, text, next - text);
- text = next + 1;
- }
- size += TextLength(rp, text, strlen(text));
- return (size);
- }
-
-
- //
- // Affiche un texte avec un hotkey
- //
- VOID MyText(struct RastPort *rp, STRPTR text, BOOL hotkey)
- {
- STRPTR next;
-
- if (hotkey)
- if (next = strchr(text, '_'))
- {
- Text(rp, text, next - text);
- SetSoftStyle(rp, FSF_UNDERLINED, -1);
- text = next + 1;
- Text(rp, text, 1);
- SetSoftStyle(rp, FS_NORMAL, -1);
- text++;
- }
- Text(rp, text, strlen(text));
- }
-
-
- //
- // Affiche un texte par rapport a une boite
- //
- VOID PrintLabelText(struct RastPort *rp, struct Box *box, STRPTR text, UWORD Flags)
- {
- UWORD width;
- WORD dx, dy;
-
- width = MyTextWidth(rp, text, Flags & LABEL_HOT_KEY);
-
- // calcule la position du texte par rapport a la boite
- if (Flags & (LABEL_ABOVE|LABEL_BELOW|LABEL_INSIDE))
- dx = (box->w - width) / 2;
-
- if (Flags & (LABEL_RIGHT|LABEL_LEFT|LABEL_INSIDE))
- dy = (box->h - rp->Font->tf_YSize) / 2;
-
- if (Flags & LABEL_ABOVE)
- dy = -VERT_DELTA - rp->Font->tf_YSize;
-
- if (Flags & LABEL_BELOW)
- dy = VERT_DELTA + box->h;
-
- if (Flags & LABEL_RIGHT)
- dx = HORIZ_DELTA + box->w;
-
- if (Flags & LABEL_LEFT)
- dx = -HORIZ_DELTA - width;
-
- SetDrMd(rp, JAM1);
- Move(rp, box->x + dx, box->y + dy + rp->Font->tf_Baseline);
- MyText(rp, text, Flags & LABEL_HOT_KEY);
- }
-
-
- //
- // Efface un label
- //
- VOID EraseLabelText(struct RastPort *rp, struct Box *box, STRPTR text, UWORD Flags)
- {
- UWORD width;
- UWORD x, y;
-
- width = MyTextWidth(rp, text, Flags & LABEL_HOT_KEY);
- x = box->x;
- y = box->y;
-
- // calcule la position du texte par rapport a la boite
- if (Flags & (LABEL_ABOVE|LABEL_BELOW|LABEL_INSIDE))
- x += ((box->w - width) / 2);
-
- if (Flags & (LABEL_RIGHT|LABEL_LEFT|LABEL_INSIDE))
- y += ((box->h - rp->Font->tf_YSize) / 2);
-
- if (Flags & LABEL_ABOVE)
- y -= (VERT_DELTA + rp->Font->tf_YSize);
-
- if (Flags & LABEL_BELOW)
- y += (VERT_DELTA + box->h);
-
- if (Flags & LABEL_RIGHT)
- x += (HORIZ_DELTA + box->w);
-
- if (Flags & LABEL_LEFT)
- x -= (HORIZ_DELTA + width);
-
- SetDrMd(rp, JAM1);
- SetAPen(rp, BackPen);
- RectFill(rp, x, y, x + width - 1, y + rp->Font->tf_YSize - 1);
- }
-